You can only use Object in a LinkedList., this
means you cant use Java Primitives. However, what you seem to need is a Map
structure.
I recommend using java.util.HashMap, it allows
you to create a Key, Value pairs.
Example:
LinkedHashMap<String, Integer> b = newLinkedHashMap<String,Integer>();
b.put("one",1);
b.put("two",2);
b.put("a",3);
for (String key:b.keySet())
{
System.out.println(b.get(key)); //
print 1 then 2 finally 3
}
Hope this is what you were asking (if so, modify
your question).
Liked By
Write Answer
How to Create an LinkedList<String, int>
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy
Join MindStick Community
You have need login or register for voting of answers or question.
Anonymous User
04-Oct-2013You can only use Object in a LinkedList., this means you cant use Java Primitives. However, what you seem to need is a Map structure.
I recommend using java.util.HashMap, it allows you to create a Key, Value pairs.
Example:
LinkedHashMap<String, Integer> b = new LinkedHashMap<String,Integer>();
b.put("one",1);
b.put("two",2);
b.put("a",3);
for (String key:b.keySet())
{
System.out.println(b.get(key)); // print 1 then 2 finally 3
}
Hope this is what you were asking (if so, modify your question).